/********************************************************
*  Monica Jimenez Anton                                 *
*  Juan Luis Martinez Cesteros                          *
*  Practicas - IGr                                     *
********************************************************/
#include <vcl.h>
#pragma hdrstop

#include "malla.h"


//---------------------------------------------------------------------------

#pragma package(smart_init)

Malla::~Malla(){
        for(int i=0;i<nV;i++){
                delete vertice[i];
        }
        delete []vertice;
        for(int i=0;i<nN;i++){
                delete normal[i];
        }
        delete [] normal;
        for(int i=0;i<nC;i++){
                delete cara[i];
        }
        delete [] cara;
}

void Malla::draw(){
  glPushMatrix();
    glMultMatrixf(this->marco_de_coordenadas->m);
         
        for(int i=0;i<nC;i++){
                if (estilo == 1)
                        glBegin(GL_LINE_LOOP);
                else
                        glBegin(GL_POLYGON);

                int vertices_cara = cara[i]->getNv();
                for(int j=0; j<vertices_cara ;j++){
                        int iV=cara[i]->getIv(j);
                        int iN=cara[i]->getIn(j);
                        glNormal3f(normal[iN]->getX(),
                                   normal[iN]->getY(),
                                   normal[iN]->getZ());
                        glVertex3f(vertice[iV]->getX(),
                                   vertice[iV]->getY(),
                                   vertice[iV]->getZ());
                }
                glEnd();
        }
  glPopMatrix();
}
